package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.Reconciliation;
import com.ruoyi.finance.service.IReconciliationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 收入支出核销Controller
 *
 * @author lmj
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/reconciliation")
public class ReconciliationController extends BaseController {
    @Autowired
    private IReconciliationService reconciliationService;

    /**
     * 查询收入支出核销列表
     */
    @RequiresPermissions("finance:reconciliation:list")
    @GetMapping("/list")
    public TableDataInfo list(Reconciliation reconciliation) {
        startPage();
        List<Reconciliation> list = reconciliationService.selectReconciliationList(reconciliation);
        return getDataTable(list);
    }

    @RequiresPermissions("finance:reconciliation:list")
    @GetMapping("/getProfit")
    public AjaxResult getProfit(Reconciliation reconciliation) {
        return AjaxResult.success(reconciliationService.getProfit(reconciliation));
    }


    /**
     * 导出收入支出核销列表
     */
    @RequiresPermissions("finance:reconciliation:export")
    @Log(title = "收入支出核销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Reconciliation reconciliation) {
        List<Reconciliation> list = reconciliationService.selectReconciliationList(reconciliation);
        ExcelUtil<Reconciliation> util = new ExcelUtil<Reconciliation>(Reconciliation.class);
        util.exportExcel(response, list, "收入支出核销数据");
    }

    /**
     * 获取收入支出核销详细信息
     */
    @RequiresPermissions("finance:reconciliation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(reconciliationService.selectReconciliationById(id));
    }

    /**
     * 新增收入支出核销
     */
    @RequiresPermissions("finance:reconciliation:add")
    @Log(title = "收入支出核销", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Reconciliation reconciliation) {
        return toAjax(reconciliationService.insertReconciliation(reconciliation));
    }

    /**
     * 修改收入支出核销
     */
    @RequiresPermissions("finance:reconciliation:edit")
    @Log(title = "收入支出核销", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Reconciliation reconciliation) {
        return toAjax(reconciliationService.updateReconciliation(reconciliation));
    }

    /**
     * 删除收入支出核销
     */
    @RequiresPermissions("finance:reconciliation:remove")
    @Log(title = "收入支出核销", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(reconciliationService.deleteReconciliationByIds(ids));
    }
}
